<template>
  <div>
    <el-table :data="getBanner" border style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="title" label="轮播图标题" width="180"> </el-table-column>
      <el-table-column prop="img" label="图片">
        <template slot-scope="item">
          <div>
            <img v-if="item.row.img" :src="item.row.img" class="imgUrl" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button type="primary" size="mini" plain @click="edit(item.row.id)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" plain @click="del(item.row.id)"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { bannerDelete } from "../../request/api.js";
export default {
  data() {
    return {};
  },
  methods: {
    // 编辑
    edit(id) {
      this.$emit("edit", id);
    },
    // 删除
    del(id) {
      this.$confirm("你确定要删除？？？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          bannerDelete({ id }).then((res) => {
            // console.log(res);
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.getBannerListactions();
              // this.$store.dispatch("user/getUserListAction");
              // this.$store.dispatch('user/getUserCount')
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 辅助函数
    ...mapActions({
      getBannerListactions: "banner/getBannerListactions",
    }),
  },
  mounted() {
    // console.log(this.getBanner);
    // console.log(this.getBannerListactions());
    this.getBannerListactions();
  },
  watch: {},
  computed: {
    ...mapGetters({
      getBanner: "banner/getBanner",
    }),
  },
  filters: {},
  components: {},
};
</script>
<style scoped>
.imgUrl {
  width: 60px;
  height: 60px;
}
</style>
